/*
 * Login.java
 *
 * Created on November 16, 2007, 2:29 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package moving2;

import java.beans.PropertyVetoException;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;

/**
 *
 * @author Administrator
 */
public class Login extends javax.swing.JInternalFrame {
    static int openFrameCount = 3;
    static final int xOffset = 30, yOffset = 30;    


    /** Creates a new instance of Login */
    public Login() {
        super("Login", 
              false, //resizable
              true, //closable
              false, //maximizable
              false);//iconifiable
        
        //...Then set the window size or call pack...
        setContentPane(createContentPane());
        
        setSize(300,210);

        //Set the window's location.
        setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
        
        System.out.println(moving2.forms.LoginForm.passwordTF.getPassword());        

        moving2.forms.LoginForm.loginBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginBTActionPerformed(evt);
            }
        });

        moving2.forms.LoginForm.cancelBT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelBTActionPerformed(evt);
            }
        });      
        
    }

    private void loginBTActionPerformed(java.awt.event.ActionEvent evt) {
        String name = (String) moving2.forms.LoginForm.loginameCB.getSelectedItem();
        char[] pass = moving2.forms.LoginForm.passwordTF.getPassword();
        System.out.println(name);
        System.out.println(pass);
        /*
        javax.swing.JOptionPane.showMessageDialog(this, 
            "Welcome to Columbus, Chevron Texaco","Login Successful", 
            javax.swing.JOptionPane.INFORMATION_MESSAGE);
        closeIFrame();
        */
        
        javax.swing.JOptionPane.showMessageDialog(this, 
                "Invalid name or password. Login again!","Login Failed", javax.swing.JOptionPane.WARNING_MESSAGE);          
        soaplogin();
    }

    private void soaplogin() {
        
        http.Opentonesoap service = new http.OpentonesoapLocator();
        http.OpentonesoapPortType soap = null;
        try {
            soap = service.getopentonesoapPort();
        } catch (ServiceException ex) {
            ex.printStackTrace();
        }
        http.AuthenticateUserResult res = null;
        try {
            res = soap.authenticateUser(new http.AuthenticateUserRequest("dondon.babao", "xxxxx", "127.0.0.1"));
        } catch (RemoteException ex) {
            ex.printStackTrace();
        }
        System.out.println(res.getResponseNo());
        System.out.println(res.getResponseMessage());
        System.out.println(res.getSessionUser());
        System.out.println(res.getSessionGroup());
        System.out.println(res.getSessionID());
        System.out.println(res.getDistributorInfo());
        System.out.println(res.getFirstName());
        System.out.println(res.getLastName());   
        
    }
    private void cancelBTActionPerformed(java.awt.event.ActionEvent evt) {
        closeIFrame();
    }
        
    private void closeIFrame() {
        try {
            setClosed(true);
        } catch (PropertyVetoException ex) {
            ex.printStackTrace();
        }        
    }
    
    private java.awt.Container createContentPane() {            

        javax.swing.JPanel loginpanel;

        loginpanel = new moving2.forms.LoginForm();
        loginpanel.setOpaque(true); 
        
        //System.out.println(moving2.forms.LoginForm.passwordTF.getPassword());
        
        //System.out.println("11");

        return loginpanel;

    } 
    
}
